﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:APP_PROCONINFO
	/// </summary>
	public partial class APP_PROCONINFO : BaseDAL<GSLMS.Entity.TB_APP_PROCONINFO>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public APP_PROCONINFO()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_APP_PROCONINFO model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_REGINFOID", model.REGINFOID),
								new OracleParameter("P_CONNAME", model.CONNAME),
								new OracleParameter("P_GENDER", model.GENDER),
								new OracleParameter("P_RELATION", model.RELATION),
								new OracleParameter("P_CORPNAME", model.CORPNAME),
								new OracleParameter("P_TELCODE", model.TELCODE),
								new OracleParameter("P_TEL", model.TEL),
								new OracleParameter("P_TELSUB", model.TELSUB),
								new OracleParameter("P_CORPADDR", model.CORPADDR),
								new OracleParameter("P_HOUADDR", model.HOUADDR),
								new OracleParameter("P_HOUTELCODE", model.HOUTELCODE),
								new OracleParameter("P_HOUTEL", model.HOUTEL),
								new OracleParameter("P_MOBILE1", model.MOBILE1),
								new OracleParameter("P_MOBILE2", model.MOBILE2),
								new OracleParameter("P_ISKNOW", model.ISKNOW),
								new OracleParameter("P_COMMOD", model.COMMOD),
								new OracleParameter("P_REMARK", model.REMARK),
								new OracleParameter("P_SPAREFIELD1", model.SPAREFIELD1),
								new OracleParameter("P_SPAREFIELD2", model.SPAREFIELD2),
								new OracleParameter("P_SPAREFIELD3", model.SPAREFIELD3)};
  
			for (int i = 0; i < 22; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

            try
            {
                int num = OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_proconinfo_add", parms);
                if (num == 1)
                    flag = true;
            }
            catch (Exception ex)
            {
                log.ExceptionHand(ex);
            }
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_APP_PROCONINFO model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_PROID", model.PROID),
								new OracleParameter("P_REGINFOID", model.REGINFOID),
								new OracleParameter("P_CONNAME", model.CONNAME),
								new OracleParameter("P_GENDER", model.GENDER),
								new OracleParameter("P_RELATION", model.RELATION),
								new OracleParameter("P_CORPNAME", model.CORPNAME),
								new OracleParameter("P_TELCODE", model.TELCODE),
								new OracleParameter("P_TEL", model.TEL),
								new OracleParameter("P_TELSUB", model.TELSUB),
								new OracleParameter("P_CORPADDR", model.CORPADDR),
								new OracleParameter("P_HOUADDR", model.HOUADDR),
								new OracleParameter("P_HOUTELCODE", model.HOUTELCODE),
								new OracleParameter("P_HOUTEL", model.HOUTEL),
								new OracleParameter("P_MOBILE1", model.MOBILE1),
								new OracleParameter("P_MOBILE2", model.MOBILE2),
								new OracleParameter("P_ISKNOW", model.ISKNOW),
								new OracleParameter("P_COMMOD", model.COMMOD),
								new OracleParameter("P_REMARK", model.REMARK),
								new OracleParameter("P_SPAREFIELD1", model.SPAREFIELD1),
								new OracleParameter("P_SPAREFIELD2", model.SPAREFIELD2),
								new OracleParameter("P_SPAREFIELD3", model.SPAREFIELD3)};
  
			for (int i = 0; i < 22; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

            try
            {
                int num = OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_proconinfo_update", parms);
                if (num == 1)
                    flag = true;
            }
            catch (Exception ex)
            {
                log.ExceptionHand(ex);
            }
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

                try
                {
                    int num = OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_proconinfo_delete", parms);
                    if (num == 1)
                        flag = true;
                }
                catch (Exception ex)
                {
                    log.ExceptionHand(ex);
                }
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_APP_PROCONINFO DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_APP_PROCONINFO model = new GSLMS.Entity.TB_APP_PROCONINFO();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["PROID"]!=null && dr["PROID"].ToString()!="")
				{
					model.PROID=OracleHelper.ToLong(dr["PROID"].ToString());
				}
				if(dr["REGINFOID"]!=null && dr["REGINFOID"].ToString()!="")
				{
					model.REGINFOID=OracleHelper.ToLong(dr["REGINFOID"].ToString());
				}
				if(dr["CONNAME"]!=null && dr["CONNAME"].ToString()!="")
				{
					model.CONNAME=dr["CONNAME"].ToString();
				}
				if(dr["GENDER"]!=null && dr["GENDER"].ToString()!="")
				{
					model.GENDER=dr["GENDER"].ToString();
				}
				if(dr["RELATION"]!=null && dr["RELATION"].ToString()!="")
				{
					model.RELATION=dr["RELATION"].ToString();
				}
				if(dr["CORPNAME"]!=null && dr["CORPNAME"].ToString()!="")
				{
					model.CORPNAME=dr["CORPNAME"].ToString();
				}
				if(dr["TELCODE"]!=null && dr["TELCODE"].ToString()!="")
				{
					model.TELCODE=dr["TELCODE"].ToString();
				}
				if(dr["TEL"]!=null && dr["TEL"].ToString()!="")
				{
					model.TEL=dr["TEL"].ToString();
				}
				if(dr["TELSUB"]!=null && dr["TELSUB"].ToString()!="")
				{
					model.TELSUB=dr["TELSUB"].ToString();
				}
				if(dr["CORPADDR"]!=null && dr["CORPADDR"].ToString()!="")
				{
					model.CORPADDR=dr["CORPADDR"].ToString();
				}
				if(dr["HOUADDR"]!=null && dr["HOUADDR"].ToString()!="")
				{
					model.HOUADDR=dr["HOUADDR"].ToString();
				}
				if(dr["HOUTELCODE"]!=null && dr["HOUTELCODE"].ToString()!="")
				{
					model.HOUTELCODE=dr["HOUTELCODE"].ToString();
				}
				if(dr["HOUTEL"]!=null && dr["HOUTEL"].ToString()!="")
				{
					model.HOUTEL=dr["HOUTEL"].ToString();
				}
				if(dr["MOBILE1"]!=null && dr["MOBILE1"].ToString()!="")
				{
					model.MOBILE1=dr["MOBILE1"].ToString();
				}
				if(dr["MOBILE2"]!=null && dr["MOBILE2"].ToString()!="")
				{
					model.MOBILE2=dr["MOBILE2"].ToString();
				}
				if(dr["ISKNOW"]!=null && dr["ISKNOW"].ToString()!="")
				{
                    model.ISKNOW = OracleHelper.ToInt(dr["ISKNOW"].ToString());
				}
				if(dr["COMMOD"]!=null && dr["COMMOD"].ToString()!="")
				{
					model.COMMOD=dr["COMMOD"].ToString();
				}
				if(dr["REMARK"]!=null && dr["REMARK"].ToString()!="")
				{
					model.REMARK=dr["REMARK"].ToString();
				}
				if(dr["SPAREFIELD1"]!=null && dr["SPAREFIELD1"].ToString()!="")
				{
                    model.SPAREFIELD1 = OracleHelper.ToInt(dr["SPAREFIELD1"].ToString());
				}
				if(dr["SPAREFIELD2"]!=null && dr["SPAREFIELD2"].ToString()!="")
				{
					model.SPAREFIELD2=dr["SPAREFIELD2"].ToString();
				}
				if(dr["SPAREFIELD3"]!=null && dr["SPAREFIELD3"].ToString()!="")
				{
					model.SPAREFIELD3=dr["SPAREFIELD3"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_APP_PROCONINFO GetByID(long ID)
		{
			GSLMS.Entity.TB_APP_PROCONINFO sModel = new GSLMS.Entity.TB_APP_PROCONINFO();
			string sql = "";
			sql = "select * from TB_APP_PROCONINFO where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_APP_PROCONINFO> GetList(GSLMS.Entity.TB_APP_PROCONINFO searchParam)
		{
			var list=new List<GSLMS.Entity.TB_APP_PROCONINFO>();
			DataTable dt = null;
			string tblName = "TB_APP_PROCONINFO";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 0;

           

            if (searchParam.PROID > 0)
                sqlWhere += " and proid=" + searchParam.PROID.ToString();

			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_APP_PROCONINFO model = new GSLMS.Entity.TB_APP_PROCONINFO();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

        /// <summary>
        /// 通过申请登记记录ID提取所有联系人信息，可以使用于立项申请中的联系人维护页面
        /// </summary>
        /// <param name="proInfoID">立项申请记录ID</param>
        /// <returns></returns>
        public List<GSLMS.Entity.TB_APP_PROCONINFO> GetAllByProInfoID(long proInfoID)
        {
            var list = new List<GSLMS.Entity.TB_APP_PROCONINFO>();

            string sql = "";
            DataTable dt = null;

            sql = "select * from TB_APP_PROCONINFO where ProID=" + proInfoID.ToString();
            DataSet ds = OracleHelper.ExecuteDataset(sql);
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }

            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    GSLMS.Entity.TB_APP_PROCONINFO model = new GSLMS.Entity.TB_APP_PROCONINFO();
                    model = DataRowToModel(dt.Rows[i]);
                    list.Add(model);
                }
            }
           

            return list;
        }


		#endregion  Method
	}
}

